<?php
class admin_listController extends adminController{

    
    //字段列表
    public function index()
    {
        $mid=intval($_GET['mid']);
        $this->alert_str($mid,'int');
        $this->info=model('expand_model')->info($mid);
        $this->list=model('expand_model_field')->field_list($mid);
        $this->show();
    }

    public function field_data_check($data)
    {
        if(model('expand_model_field')->field_info($data['field'],$data['mid'],$data['fid'])){
            $this->msg('字段不能重复！',0);
        }
    }

    public function data_info()
    {
        $data['field_type']=model('expand_model_field')->field_type();
        return $data;
    }

    //字段添加
    public function add()
    {
        $mid=intval($_GET['mid']);
        $this->alert_str($mid,'int');
        $this->view()->assign($this->data_info());
        $this->model_info=model('expand_model')->info($mid); 
        $this->action_name='添加';
        $this->action='add';
        $this->show('admin_list/info');
    }

    public function add_save()
    {
        //录入模型处理
        $mid=intval($_POST['mid']);
        $this->alert_str($mid,'int',true);
        $this->field_data_check($_POST);
        model('expand_model_field')->field_add($_POST);
        $this->msg('字段添加成功！',1);
    }

    //字段修改
    public function edit()
    {
        $fid=intval($_GET['fid']);
        $this->alert_str($fid,'int');
        $this->view()->assign($this->data_info());
        $this->info=model('expand_model_field')->field_info_id($fid);
        $this->model_info=model('expand_model')->info($this->info['mid']);
        $this->action_name='编辑';
        $this->action='edit';
        $this->show('admin_list/info');
    }

    public function edit_save()
    {
        
        //录入模型处理
        $fid=intval($_POST['fid']);
        $this->alert_str($fid,'int',true);
        $this->field_data_check($_POST);
        $id=model('expand_model_field')->field_edit($_POST);
        $this->msg('字段修改成功！',1);
    }

    //字段删除
    public function del()
    {
        $mid=intval($_POST['mid']);
        $this->alert_str($mid,'int',true);
        $fid=intval($_POST['fid']);
        $this->alert_str($fid,'int',true);
        //录入模型处理
        model('expand_model_field')->field_del($_POST);
        $this->msg('字段删除成功！',1);

    }

    //获取内容字段
    public function get_field()
    {
        $cid=intval($_POST['cid']);
        $aid=intval($_POST['aid']);
        if(empty($cid)){
            return;
        }
        $category_info=api('admin','category_info',$cid);
        if(empty($category_info['expand'])){
            return;
        }
        //获取字段列表
        $list=model('expand_model_field')->field_list($category_info['expand']);
        if(empty($list)){
            return;
        }
        $html='';
        $js='';
        $info=model('expand_model_field')->get_file_content($aid,$category_info['expand']);
        foreach ($list as $value) {
            $field_info=model('expand_model_field')->field_info_id($value['fid']);
            $html.=model('expand_model_field')->get_layout_html($field_info,$info[$value['field']]);  
        }
        echo $html;
    }
}